<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      body {
        text-align: center;
      }
      .father {
        background-color: pink;
        width: 300px;
        height: 300px;
        margin: 0 auto;
      }
      .son {
        width: 200px;
        height: 200px;
        background-color: skyblue;
        margin: 0 auto;
      }
      .w {
        background-color: rgb(134, 245, 139);
        height: 100px;
        border: 10px solid #000;
        margin: 20px;
        padding: 20px;
      }
    </style>
  </head>
  <body>
    <div class="father">
      <div class="son"></div>
    </div>
    <div class="w"></div>
    <script>
      // offset 系列
      var father = document.querySelector('.father');
      var son = document.querySelector('.son');
      var w = document.querySelector('.w');
      //1.获取父定位元素 如果父元素不是定位的就一直往上找 直到body
      console.log(son.offsetParent); // body
      //2. 获取相对于父定位元素 的left 和top 的便宜
      console.log(son.offsetLeft); //293
      console.log(son.offsetTop); //0

      //3. 获取元素自己的宽度 height  width   +padding  + border
      console.log(w.offsetWidth); //   浏览器宽度变化
      console.log(w.offsetHeight); //160     边框10  padding20
    </script>
  </body>
</html>
